#include "tinyxml2.h"
#include <iostream>

using namespace tinyxml2;
using namespace std;

int main( int argc, const char ** argv )
{
    int a = -1;
    size_t b = static_cast<size_t>(a);
    cout << "b = " << b << endl;

    XMLDocument doc;
    if(doc.LoadFile("read.xml") != XML_SUCCESS) {
        cout << "[" << doc.ErrorName() << "] read xml failed." << endl;
        return -1;
    }
    // doc.Print();

#if 1
    XMLElement *root = doc.RootElement();
    cout << root->Name() << endl;
    XMLElement *teaNode = root->FirstChildElement();
    cout << teaNode->Name() << ", " << teaNode->FindAttribute("name")->Name() << ", " 
        << teaNode->FindAttribute("name")->Value() << ", " << teaNode->GetText() << endl;


    XMLElement *stuNode = teaNode->NextSiblingElement();
    // XMLElement *stuNode = root->FirstChildElement("Student");
    if(stuNode == nullptr) {
        cout << "stu nude is null." << endl;
        return -1;
    }
    XMLElement *m = stuNode->FirstChildElement();
    while (m)
    {
        cout << m->Name() << ", " << m->FindAttribute("sex")->Name() << ", " 
            << m->FindAttribute("sex")->Value() << ", " << m->GetText() << endl;
        m = m->NextSiblingElement();
    }
#endif
    
    return 0;
}